package com.qbw.app.module.common.view;

import android.content.Context;
import androidx.annotation.Nullable;
import android.util.AttributeSet;

/**
 * @author QBW
 * @date 2019-11-27
 * 显示斜体的时候有时候显示不全，在最后面增加一个空格
 */
public class TextViewShowItalic extends androidx.appcompat.widget.AppCompatTextView {
    public TextViewShowItalic(Context context) {
        super(context);
    }

    public TextViewShowItalic(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public TextViewShowItalic(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    /*@Override
    public void setText(CharSequence text, BufferType type) {
        super.setText(text + " ", type);
    }

    @Override
    public CharSequence getText() {
        CharSequence text = super.getText();
        if (text.length() > 0 && ' ' == text.charAt(text.length() - 1)) {
            text = text.subSequence(0, text.length() - 1);
        }
        return text;
    }*/

    @Override
    protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        final int measuredWidth = getMeasuredWidth();
        final float tenPercentOfMeasuredWidth = measuredWidth * 0.1f;
        final int newWidth = measuredWidth + (int) tenPercentOfMeasuredWidth;

        setMeasuredDimension(newWidth, getMeasuredHeight());
    }
}
